package com.fs.system.college_admin.controller;

import com.fs.system.college_admin.domain.CollegeAdmin;
import com.fs.system.college_admin.domain.End;
import com.fs.system.college_admin.domain.Given;
import com.fs.system.college_admin.service.CollegeAdminService;
import com.fs.system.common.ResponseData;
import com.fs.system.student.domain.ApplicationRecord;
import com.fs.system.teacher.domain.First;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/collegeAdmin")
public class CollegeAdminController {

    @Resource
    private CollegeAdminService collegeAdminService;

    @PostMapping("/add")
    public ResponseData addCollegeAdmin(@RequestBody CollegeAdmin collegeAdmin) {
        collegeAdminService.addCollegeAdmin(collegeAdmin);
        return new ResponseData("200", "添加成功");
    }

    @GetMapping("/selectAll")
    public ResponseData getCollegeAdminList(CollegeAdmin collegeAdmin){
        System.out.println(collegeAdmin);
        List<CollegeAdmin> collegeAdminList = collegeAdminService.getCollegeAdminList(collegeAdmin);
        return new ResponseData("200","查询成功",collegeAdminList);
    }

    @GetMapping("/selectPage")
    public ResponseData selectPage(
            CollegeAdmin collegeAdmin,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        PageInfo<CollegeAdmin> collegeAdminPageInfo = collegeAdminService.selectPage(collegeAdmin,pageNum, pageSize);
        return new ResponseData("200", "查询成功",collegeAdminPageInfo);
    }

    @PutMapping("/update")
    public ResponseData updateCollegeAdmin(@RequestBody CollegeAdmin collegeAdmin){
        collegeAdminService.updateCollegeAdmin(collegeAdmin);
        return new ResponseData("200","更新成功");
    }

    /**
     * 逻辑删除
     */
    @PutMapping("/deleteCollegeAdmin/{adminId}/{updateBy}")
    public ResponseData deleteCollegeAdmin(@PathVariable Long adminId, @PathVariable String updateBy) {
        collegeAdminService.deleteCollegeAdmin(adminId, updateBy);
        return new ResponseData("200", "删除成功");
    }

    /**
     * 批量删除
     * @param
     * @return
     */
    @PutMapping("/deleteCollegeAdminBatch/{updateBy}")
    public ResponseData deleteBatch(
            @PathVariable String updateBy,
            @RequestBody List<Long> ids
    ){
        System.out.println(ids);
        collegeAdminService.deleteBatch(ids,updateBy);
        return new ResponseData("200", "批量删除成功");
    }

    /**
     * 院长获取待终审的记录，根据teaId列表查询
     * 查询的是最近一周的数据
     */
    @GetMapping("/getEnd")
    public ResponseData getEnd(@RequestParam("teaList") List<Integer> teaList,
                                 @RequestParam(defaultValue = "1")Integer page,
                                 @RequestParam(defaultValue = "5")Integer size){
       PageInfo<ApplicationRecord> list = collegeAdminService.getEnd(teaList,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 院长查看一周前的记录
     */
    @GetMapping("/getEnd2")
    public ResponseData getEnd2(@RequestParam("teaList") List<Integer> teaList,
                               @RequestParam(defaultValue = "1")Integer page,
                               @RequestParam(defaultValue = "5")Integer size){
        PageInfo<ApplicationRecord> list = collegeAdminService.getEnd2(teaList,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 院长终审材料
     */
    @PutMapping("/endCheck")
    public ResponseData endCheck(@RequestBody ApplicationRecord applicationRecord){
        collegeAdminService.endCheck(applicationRecord);
        return new ResponseData("200","修改成功");
    }

    /**
     * 院长终审后，添加一条终审记录
     */
    @PostMapping("/endRecord")
    public ResponseData endRecord(@RequestBody End end){
        collegeAdminService.endRecord(end);
        return new ResponseData("200","添加成功");
    }

    /**
     * 院长获取审核记录列表
     */
    @GetMapping("/getRecord")
    public ResponseData getRecord(End end,
                                  @RequestParam(defaultValue = "1")Integer page,
                                  @RequestParam(defaultValue = "5")Integer size){
        PageInfo<End> list = collegeAdminService.getRecord(end,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 根据记录id查询记录信息
     */
    @GetMapping("/getRecordById")
    public ResponseData getRecordById(End end,
                                      @RequestParam(defaultValue = "1")Integer page,
                                      @RequestParam(defaultValue = "5")Integer size){
        ApplicationRecord list = collegeAdminService.getRecordById(end,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 院长获取分配记录表
     */
    @GetMapping("/getGivenRecord")
    public ResponseData getGivenRecord(Given given,
                                       @RequestParam(defaultValue = "1")Integer page,
                                       @RequestParam(defaultValue = "5")Integer size){
        PageInfo<Given> list = collegeAdminService.getGivenRecord(given,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 根据分配记录id查询分配记录信息
     */
    @GetMapping("/getGivenById")
    public ResponseData getGivenById(Given given,
                                      @RequestParam(defaultValue = "1")Integer page,
                                      @RequestParam(defaultValue = "5")Integer size){
        ApplicationRecord list = collegeAdminService.getGivenById(given,page,size);
        return new ResponseData("200","查询成功",list);
    }
}
